/*     */ package com.qmsk.business.store.warehouse.controller;
/*     */ 
/*     */ import com.qmsk.business.store.rack.dao.RackDao;
/*     */ import com.qmsk.business.store.warehouse.dao.WarehouseDao;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/wareHouse"})
/*     */ public class WarehouseController
/*     */ {
/*  39 */   private static final Logger logger = Logger.getLogger(WarehouseController.class);
/*     */ 
/*     */   @Autowired
/*     */   private WarehouseDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private RackDao rackDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  61 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  63 */       GsonEbRst gsonEbRst = null;
/*     */ 
/*  65 */       Map params = new HashMap();
/*     */ 
/*  67 */       MapUtils.addToMap(params, "id", RequestUtils.getLong(request, "id"));
/*  68 */       MapUtils.addToMap(params, "sId", shopId);
/*  69 */       MapUtils.addToMap(params, "status", 
/*  70 */         RequestUtils.getShort(request, "status"));
/*     */ 
/*  72 */       MapUtils.addPercentToMap(params, "code", 
/*  73 */         RequestUtils.getString(request, "code"));
/*  74 */       MapUtils.addPercentToMap(params, "name", 
/*  75 */         RequestUtils.getString(request, "name"));
/*  76 */       MapUtils.addPercentToMap(params, "address", 
/*  77 */         RequestUtils.getString(request, "address"));
/*     */ 
/*  79 */       gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*     */ 
/*  81 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     }
/*     */     catch (Exception e) {
/*  84 */       logger.error(e);
/*     */ 
/*  86 */       ResponseUtils.setErrorMsgResponse(
/*  87 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("id") Long id)
/*     */   {
/*     */     try
/*     */     {
/*  96 */       Map params = new HashMap();
/*  97 */       MapUtils.addToMap(params, "id", id);
/*     */ 
/*  99 */       MapUtils.addToMap(params, "sId", shopId);
/* 100 */       MapUtils.addToMap(params, "status", 
/* 101 */         RequestUtils.getShort(request, "status"));
/*     */ 
/* 103 */       MapUtils.addPercentToMap(params, "code", 
/* 104 */         RequestUtils.getString(request, "code"));
/* 105 */       MapUtils.addPercentToMap(params, "name", 
/* 106 */         RequestUtils.getString(request, "name"));
/* 107 */       MapUtils.addPercentToMap(params, "address", 
/* 108 */         RequestUtils.getString(request, "address"));
/* 109 */       GsonEbRst gsonEbRst = this.dao.getGsonOfId(params);
/* 110 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 112 */       logger.error(e);
/* 113 */       ResponseUtils.setErrorMsgResponse(
/* 114 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/* 134 */       int nResult = 0;
/* 135 */       int nResult_rack = 0;
/* 136 */       GsonHeadOneRow gsonHRow = null;
/*     */ 
/* 138 */       String sData = RequestUtils.getStringOfData(request);
/*     */ 
/* 140 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 141 */       if ((p != null) && (p.isExistsInsertRows())) {
/* 142 */         for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 143 */           String status = (String)((GsonHeadOneRow)p.getListInsertRows().get(i))
/* 144 */             .getValueOfName("status");
/* 145 */           if (!(StringUtils.isEmpty(status))) continue;
/* 146 */           ((GsonHeadOneRow)p.getListInsertRows().get(i))
/* 147 */             .autoAddHeadData("status", Integer.valueOf(-1));
/*     */         }
/*     */ 
/* 150 */         nResult = this.dao.applyUpdates(p, "id");
/*     */ 
/* 152 */         gsonHRow = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 153 */         if (gsonHRow != null) {
/* 154 */           GsonHeadOneRow row = new GsonHeadOneRow(new String[0], 
/* 155 */             new Object[0]);
/* 156 */           row.autoAddHeadData("houseId", 
/* 157 */             gsonHRow.getValueOfName("id"));
/* 158 */           row.autoAddHeadData("code", 
/* 159 */             Long.valueOf(System.currentTimeMillis() / 1000L));
/* 160 */           row.autoAddHeadData("name", gsonHRow.getValueOfName("name"));
/* 161 */           row.autoAddHeadData("status", 
/* 162 */             (gsonHRow.getValueOfName("status") == null) ? Integer.valueOf(-1) : 
/* 163 */             gsonHRow.getValueOfName("status"));
/*     */ 
/* 165 */           nResult_rack = this.rackDao.insertGsonHeadOneRow(row);
/*     */         }
/*     */ 
/* 168 */         if ((nResult > 0) && (nResult_rack > 0))
/* 169 */           DbConnection.commit();
/*     */         else {
/* 171 */           DbConnection.rollback();
/*     */         }
/*     */       }
/*     */ 
/* 175 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 176 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 177 */         response);
/*     */     } catch (Exception e) {
/* 179 */       DbConnection.rollback();
/* 180 */       logger.error(e);
/* 181 */       ResponseUtils.setErrorMsgResponse(
/* 182 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 183 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 197 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 199 */       String[] strParams = id.split(",");
/* 200 */       Map params = new HashMap();
/* 201 */       GsonEbRst gson = null;
/* 202 */       for (String s : strParams) {
/* 203 */         params.put("hId", s);
/* 204 */         gson = this.rackDao.getGsonOfId(params);
/* 205 */         if (gson.isExistsData()) {
/* 206 */           ResponseUtils.setErrorMsgResponse("请先清空欲删除库房下的[货区/货位/货架]", 
/* 207 */             response);
/* 208 */           return;
/*     */         }
/*     */       }
/*     */ 
/* 212 */       int nResult = this.dao.deleteParams(strParams);
/*     */ 
/* 214 */       if (nResult > 0)
/* 215 */         DbConnection.commit();
/*     */       else {
/* 217 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 220 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 221 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 222 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 225 */       DbConnection.rollback();
/* 226 */       logger.error(e);
/* 227 */       ResponseUtils.setErrorMsgResponse(
/* 228 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 229 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId)
/*     */   {
/*     */     try
/*     */     {
/* 247 */       int nResult = 0;
/* 248 */       String sData = RequestUtils.getStringOfData(request);
/* 249 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*     */ 
/* 251 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 252 */         for (GsonHeadOneRow r : p.getListUpdateRows()) {
/* 253 */           Integer status = ObjectComm.objectToInteger(r
/* 254 */             .getValueOfName("status"));
/* 255 */           if ((status != null) && (status.intValue() == 0)) {
/* 256 */             Long id = ObjectComm.objectToLong(r
/* 257 */               .getValueOfName("id"));
/* 258 */             if (!(this.dao.checkStatus(shopId, id).booleanValue())) {
/* 259 */               ResponseUtils.setErrorMsgResponse("请先启用库房", 
/* 260 */                 response);
/* 261 */               return;
/*     */             }
/* 263 */             Map map = new HashMap();
/* 264 */             map.put("status", Integer.valueOf(1));
/* 265 */             map.put("hId", id);
/* 266 */             if (this.rackDao.getGsonOfId(map).isExistsData()) {
/* 267 */               ResponseUtils.setErrorMsgResponse(
/* 268 */                 "请先禁用库房下的[货区/货位/货架]", response);
/* 269 */               return;
/*     */             }
/*     */           }
/*     */         }
/* 273 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/*     */ 
/* 276 */       if (nResult > 0)
/* 277 */         DbConnection.commit();
/*     */       else {
/* 279 */         DbConnection.rollback();
/*     */       }
/* 281 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 282 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 283 */         response);
/*     */     } catch (Exception e) {
/* 285 */       logger.error(e);
/* 286 */       DbConnection.rollback();
/* 287 */       ResponseUtils.setErrorMsgResponse(
/* 288 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 289 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.warehouse.controller.WarehouseController
 * JD-Core Version:    0.5.3
 */